package top.chengdongqing.mishop.order.review

import org.springframework.http.HttpStatus
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.*
import top.chengdongqing.mishop.order.review.dto.OrderReviewDTO
import top.chengdongqing.mishop.order.review.dto.ProductReviewDTO
import top.chengdongqing.mishop.order.review.vo.OrderReviewVO
import top.chengdongqing.mishop.order.review.vo.PendingReviewOrderVO

@RestController
@RequestMapping("/orders/reviews")
class OrderReviewController(private val reviewService: OrderReviewService) {

    @GetMapping("/pending")
    fun getPendingReviewOrders(@AuthenticationPrincipal userId: Int): List<PendingReviewOrderVO> {
        return reviewService.getPendingReviewOrders(userId)
    }

    @GetMapping("/{orderId}")
    fun getOrderReview(@PathVariable orderId: Int, @AuthenticationPrincipal userId: Int): OrderReviewVO {
        return reviewService.getOrderReview(orderId, userId)
    }

    @PostMapping("/{orderId}")
    @ResponseStatus(HttpStatus.CREATED)
    fun createOrderReview(
        @PathVariable orderId: Int,
        @RequestBody orderReviewDTO: OrderReviewDTO,
        @AuthenticationPrincipal userId: Int
    ) {
        reviewService.createOrderReview(orderId, orderReviewDTO, userId)
    }

    @PostMapping("/{orderId}/{productId}")
    @ResponseStatus(HttpStatus.CREATED)
    fun createProductReview(
        @PathVariable orderId: Int,
        @PathVariable productId: Int,
        @RequestBody productReviewDTO: ProductReviewDTO,
        @AuthenticationPrincipal userId: Int
    ) {
        reviewService.createProductReview(orderId, productId, productReviewDTO, userId)
    }
}